define("login",["jquery","md5","validate"],function ($) {
    return {
        init:function () {
            $("form").validate({
                rules:{
                    uname:{
                        required:true,
                    },
                    upwd:{
                        required:true
                    }
                },
                messages: {
                    uname:{
                        required:""
                    },
                    upwd:{
                        required:""
                    }
                },
                submitHandler:function () {
                    var formData=new FormData()
                    var $dataArr=$("form").serializeArray()
                    console.log($dataArr);
                    $dataArr.forEach((ele,index)=>{
                        if(ele.name=="upwd"){
                        formData.append(ele.name,$.md5(ele.value))
                    }else{
                        formData.append(ele.name,ele.value)
                        console.log(formData);
                    }

                })
                    $.ajax({
                        type:"post",
                        url:"http://127.0.0.1/diwudadao/server/login.php",
                        dataType:"json",
                        data:formData,
                        processData:false,
                        contentType:false,
                        success:function (res) {
                            if(res.status==1){

                                alert("登录成功!");
                                window.location="index.html"
                            }

                        }
                    })
                    return false
                }
            })
        }
    }
})